﻿using CommandProcessor.Command;
using Data.Infrastructure;
using Data.Models;
using Data.Repositories;
using Domain.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Handlers
{
    public class CreateOrUpdateCategoryHandler : ICommandHandler<CreateOrUpdateCategoryCommand>
    {
        private readonly ICategoryRepository companyRepository;
        private readonly IUnitOfWork unitOfWork;
        public CreateOrUpdateCategoryHandler(ICategoryRepository companyRepository, IUnitOfWork unitOfWork)
        {
            this.companyRepository = companyRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(CreateOrUpdateCategoryCommand command)
        {
            var company = new Category
            {
                ID = command.ID,
                Description = command.Description,
                Name = command.Name,
                Remark = command.Remark
            };
            if (company.ID == 0)
                companyRepository.Add(company);
            else
                companyRepository.Update(company);

            unitOfWork.Commit();
            return new CommandResult(true);
        }
        public ICommandResult ExecuteRange(IEnumerable<CreateOrUpdateCategoryCommand> commands)
        {
            throw new NotImplementedException();
        }



        public ICommandResult DeleteRange(IEnumerable<CreateOrUpdateCategoryCommand> commands)
        {
            throw new NotImplementedException();
        }
    }
}
